﻿<Page
    x:Class="UnitDrivenRT.TestEngine"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UnitDrivenRT"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c="using:UnitDriven.Controls"
    mc:Ignorable="d">

    <Page.Resources>
        <c:TestStatusConverter x:Key="statusConverter" />
        <c:VisibilityConverter x:Key="visibilityConverter" />

        <ControlTemplate x:Key="StatusButton" TargetType="Button">
            <Ellipse 
				StrokeThickness="1"
				Height="32"
				Width="32"
				Fill="{Binding Status, Converter={StaticResource statusConverter}}" />
        </ControlTemplate>

        <DataTemplate x:Key="method">
            <Border Padding="20,10,10,10" Visibility="{Binding IsVisible}">
                <StackPanel Orientation="Horizontal">
                    <Button 
						Template="{StaticResource StatusButton}"
						Click="Run_Click" 
						IsEnabled="{Binding IsNotRunning}"
						HorizontalAlignment="Left"
						Margin="10,0,0,0" />
                    <TextBlock 
						Text="{Binding Name}" 
                        
						VerticalAlignment="Center" Style="{StaticResource GroupHeaderTextStyle}" Margin="6,0,0,0" />
                    <Button 
						Content="Error" 
						Margin="10,0,0,0"
						VerticalAlignment="Center"
                        Click="ErrorDetails_Click"
						Visibility="{Binding HasError, Converter={StaticResource visibilityConverter}}" />
                </StackPanel>
            </Border>
        </DataTemplate>

        <DataTemplate x:Key="type">
            <Border Padding="20,10,10,10" Visibility="{Binding IsVisible}" >
                <StackPanel Orientation="Vertical">
                    <StackPanel Orientation="Horizontal">
                        <Button 
							Click="Run_Click" 
							IsEnabled="{Binding IsNotRunning}"
							Template="{StaticResource StatusButton}"
							HorizontalAlignment="Left"
							Margin="10,0,0,0" />
                        <TextBlock 
							VerticalAlignment="Center" 
							Text="Type:" Style="{StaticResource GroupHeaderTextStyle}" Margin="6,0,0,0" />
                        <TextBlock 
							VerticalAlignment="Center" 
							Text="{Binding Name}" Style="{StaticResource GroupHeaderTextStyle}" />
                    </StackPanel>
                    <ItemsControl 
						ItemTemplate="{StaticResource method}" 
						ItemsSource="{Binding Items}" 
						HorizontalContentAlignment="Stretch" />
                </StackPanel>
            </Border>
        </DataTemplate>

        <DataTemplate x:Key="group">
            <Border Padding="20,10,10,10" Background="Transparent" Visibility="{Binding IsVisible}">
                <StackPanel Orientation="Vertical">
                    <StackPanel Orientation="Horizontal">
                        <Button 
							Click="Run_Click" 
							IsEnabled="{Binding IsNotRunning}"
							Template="{StaticResource StatusButton}"
							HorizontalAlignment="Left"
							Margin="10,0,0,0" VerticalAlignment="Bottom" />
                        <TextBlock 
							VerticalAlignment="Center" 
							Text="{Binding Name}" Style="{StaticResource GroupHeaderTextStyle}" Margin="6,0,0,0" />
                    </StackPanel>
                    <ItemsControl 
						ItemTemplate="{StaticResource type}" 
						ItemsSource="{Binding Items}"
						HorizontalContentAlignment="Stretch" />
                </StackPanel>
            </Border>
        </DataTemplate>
    </Page.Resources>

    <!--LayoutRoot contains the root grid where all other page content is placed-->

    <Grid x:Name="LayoutRoot" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!-- TitlePanel contains the name of the application and page title -->

        <!-- ContentPanel - place additional content here -->
        <Grid x:Name="TitlePanel" Grid.Row="0">
    		<TextBlock Text="UNIT DRIVEN" Style="{StaticResource PageHeaderTextStyle}"/>
    		<TextBlock Text="testrunner" Style="{StaticResource PageSubheaderTextStyle}" VerticalAlignment="Top" Margin="0,40,0,0" />
    	</Grid>

        <!-- ContentPanel - place additional content here -->
        <Grid x:Name="ContentGrid" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <StackPanel Grid.Row="0" Orientation="Horizontal">
                <Button Content="Run All" VerticalAlignment="Center" Click="RunAll_Click" IsEnabled="{Binding IsNotRunning}" />
                <TextBlock Text="Test Engine:" VerticalAlignment="Center" Style="{StaticResource GroupHeaderTextStyle}"/>
                <TextBlock Text="{Binding Succeeded}" Margin="5,0,0,0" VerticalAlignment="Center" Style="{StaticResource GroupHeaderTextStyle}"/>
                <TextBlock Text="/" Margin="3,0,3,0" VerticalAlignment="Center" Style="{StaticResource GroupHeaderTextStyle}"/>
                <TextBlock Text="{Binding Total}" VerticalAlignment="Center" Style="{StaticResource GroupHeaderTextStyle}"/>
                <TextBox 
					x:Name="filterText"
					Text="{Binding Filter, Mode=TwoWay}"
					Width="225"
					Margin="5,10,5,5" 
					VerticalContentAlignment="Bottom"
                    KeyUp="TextBox_KeyUp"
					GotFocus="TextBox_GotFocus" />
            </StackPanel>

            <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Visible">
                <ItemsControl 
					x:Name="types"
					Background="Black"
					ItemTemplate="{StaticResource group}"
					ItemsSource="{Binding Items}"
					HorizontalContentAlignment="Stretch" />
            </ScrollViewer>
        </Grid>

        <Border
			VerticalAlignment="Bottom"
			HorizontalAlignment="Stretch"
			BorderThickness="0"
			Background="Black"
			Grid.Row="1"
			Padding="1">
            <Grid>
                <Button
					Click="SummaryCopy_Click"
					Content="Summary" />
            </Grid>
        </Border>
    </Grid>
</Page>